package com.generator;

import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.authz.UnauthorizedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @author yz
 * @data: 2022/3/21 21:13 星期一
 * @file : NoPermissionException.java
 * <p>
 * ExceptionHandler用于捕获异常
 */
@ControllerAdvice
public class NoPermissionException {
    private static final Logger log = LoggerFactory.getLogger(NoPermissionException.class);


    /**
     * 无权限页面
     *
     * @param ex
     * @return
     */
    @ExceptionHandler(UnauthorizedException.class)
    public String handleShiroException(Exception ex) {
        return "error/unauth" ;
    }

    /**
     * 未登录前往登录
     *
     * @param ex
     * @return
     */
    @ExceptionHandler(AuthorizationException.class)
    public String authorizationException(Exception ex) {
        return "wei" ;
    }

    /**
     * 登录异常
     */
    @ExceptionHandler(LoginException.class)
    public String loginException(LoginException e) {
        return "login" ;
    }

    /**
     * token不一致
     * 跳转被下线页面
     *
     * @param e
     */

    @ExceptionHandler(NoTokenException.class)
    public String noTokenException(NoTokenException e) {
        return "error/offline" ;
    }
}
